function validate() {
    $("#formEdit")
        .validate(
        {

            rules : {
                'name' : "required",
                'address.address' : "required",
                'countries.country' : "required",
                'regions.region' : "required",
                'cities.city' : "required",
                'agreeReceivingDirectlyFromSponsor' :  "required",
                'documentApprovalDelay' :  "required" ,
                'howOftenTheyMet' : "required",
                'listOfMembersNotParticipating' : "required",
                'listOfMembersParticipating' : "required",
                'needEcapproval' : "required",
                'timelineToSubmit' : "required",
                'comiteDocencia.centro.id' : "required",
                'nextMeeting': {
                    required: true,
                    date: true
                }

            },
            messages : {
                'name' : "Name is required",
                'address.address': "Address is required",
                'countries.country' : "Country is required",
                'regions.region' : "Region is required",
                'cities.city' : "City is required",
                'agreeReceivingDirectlyFromSponsor': "Agree Receiving Directly From Sponsor is required",
                'documentApprovalDelay' :  "Document Approval Delay is required",
                'howOftenTheyMet' : "How Often They Met country is required",
                'listOfMembersNotParticipating' : "List Of Members Not Participating is required",
                'listOfMembersParticipating' : "List Of Members Participating is requeried",
                'needEcapproval' : "Need Ecapproval is required",
                'timelineToSubmit' : "Timeline To Submit is required",
                'comiteDocencia.centro.id' : "Center is required",
                'nextMeeting': { required : "Next Meeting is required"  }
            },
            errorElement : "label"

        })
}

function addRowCommitee(tableID) {

    var table = document.getElementById(tableID);

    var rowCount = table.rows.length;
    if(rowCount == 2 && table.rows[1].style.display == "none"){
        var row = table.rows[1];
        row.children[0].children[0].value = "";
        row.children[1].children[0].value = "";
        row.children[2].children[0].value = "";
        row.children[3].children[0].value = "";
        row.children[4].children[0].value = "";
        table.rows[1].style.display = "";
        return;
    }

    var counts = rowCount -1;

    var rowContact = $('#table_content tbody>tr:last').clone()[0];
    rowContact.children[0].children[0].value = '';
    rowContact.children[0].children[0].name = 'comiteDocencia.contactPersons['+ counts +'].role.id';
    rowContact.children[1].children[0].value = '';
    rowContact.children[1].children[0].name = 'comiteDocencia.contactPersons['+ counts +'].degree';
    rowContact.children[2].children[0].value = '';
    rowContact.children[2].children[0].name = 'comiteDocencia.contactPersons['+ counts +'].email';
    rowContact.children[3].children[0].value = '';
    rowContact.children[3].children[0].name = 'comiteDocencia.contactPersons['+ counts +'].fax';
    rowContact.children[4].children[0].value = '';
    rowContact.children[4].children[0].name = 'comiteDocencia.contactPersons['+ counts +'].phone';
    rowContact.children[5].children[0].onclick = function(){deleteRow('table_content',this); return false;};

    $('#table_content > tbody:last').append(rowContact);
}

function deleteRow(tableID, button) {

    var table = document.getElementById(tableID);
    if(table.rows.length == 2){
        table.rows[1].style.display = "none";
    }else{
        table.deleteRow(button.parentNode.parentNode.rowIndex);
    }
}

function beforeSaveTeachingCommittee(tableID){
    var table = document.getElementById(tableID);
    var rowCount = table.rows.length;

    if(rowCount == 2 && table.rows[1].style.display == "none"){
        table.deleteRow(1);
    }
}

